<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<?php
// check if the user is already logged-in

session_start();
if (isset($_SESSION['username'])) {
    
    include_once '../utils/includer.php';
    includeFileOnce("utils/directories.php");
    includeFileOnce("utils/redirect.php");
    
    $host = "http://" . getHostBaseDir() . "/administrator/index.php?idc=1";
    redirect($host, FALSE);
}
?>

<html>
    <head>
        <title>WebDoc - Login</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="../styles/main.css">
        <link rel="stylesheet" type="text/css" href="../styles/admin.css">

        <script type="text/javascript" src="../lib/md5.js"></script>        
        <script type="text/javascript">            
            function login() { 
                document.submitForm.username.value = document.loginForm.username.value;        
                document.submitForm.password.value = hex_md5(document.loginForm.challenge.value + hex_md5(document.loginForm.password.value));        
                document.submitForm.challenge.value = document.loginForm.challenge.value;
                document.submitForm.setcookie.value = document.loginForm.setcookie.value;                
                document.submitForm.submit();        
                return true;    
            }        
        </script>


    </head>
    <body>
        <div id="page" class="rounded">

            <div class="signin-box">
                <form id="loginForm" name="loginForm" method="post" enctype="multipart/form-data" action="#">
                    <h2>Accedi</h2>
                    <label>
                        <strong class="email-label">Username</strong>
                        <input id="Email" type="text" value="" name="username" spellcheck="false" size="35" maxlength="100">
                    </label>
                    <label>
                        <strong class="passwd-label">Password</strong>
                        <input id="Passwd" type="password" name="password" size="35" maxlength="100">
                    </label>
                    <br>
                    <input id="signIn" class="g-button g-button-submit" type="button" value="Accedi" name="signIn" onclick="login()">
                    <label class="remember">
                        <input id="PersistentCookie" type="checkbox" checked="checked" value="yes" name="setcookie">
                        <strong class="remember-label"> Resta connesso </strong>
                    </label>
                    <input type="hidden" name="challenge" value="<?php dechex(getrandmax()) ?>">
                </form>
                <form name="submitForm" method="POST" action="../protected/ActionDispatcher.php?action=login">
                    <input type="hidden" name="username" />
                    <input type="hidden" name="challenge" />
                    <input type="hidden" name="password" />
                    <input type="hidden" name="setcookie" />
                </form>
            </div>
        </div>
    </body>
</html>
